package com.yonyou.iuap.shell.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import net.sf.json.JSONObject;

import com.yonyou.iuap.pub.JsonUtils;
import com.yonyou.iuap.shell.dao.BdKnowledgeCategoryEntityDao;
import com.yonyou.iuap.shell.entity.BdCategoryRelationEntity;
import com.yonyou.iuap.shell.entity.BdKnowledgeCategoryEntity;
import com.yonyou.iuap.shell.entity.BdProductEntity;
import com.yonyou.iuap.shell.entity.exp.BdKnowledgeCategoryEntityVo;
import com.yonyou.iuap.shell.facade.IuapFacade;
import com.yonyou.iuap.shell.pub.RequestDto;
import com.yonyou.iuap.shell.pub.ResultDto;
import com.yonyou.iuap.shell.service.intf.IKmCategoryService;

/**
 * 知识分类服务层实现类
 * 
 * @author 刘桂岑
 *
 */
@Service(value = "service-kmcategory")
public class KmCategoryServiceImpl implements IKmCategoryService {

	@Autowired
	@Qualifier("Dao-BdKnowledgeCategoryEntityDao")
	private BdKnowledgeCategoryEntityDao<BdKnowledgeCategoryEntity> bdKmCategoryEntityDao;

	// 获取所有的知识分类的列表
	public List selectAll() {
		// TODO 自动生成的方法存根
		return bdKmCategoryEntityDao.selectAll();
	}

	public int deleteByPrimaryKey(String paramString) {
		// TODO 自动生成的方法存根
		return bdKmCategoryEntityDao.deleteByCondition(paramString);
	}

	public int insert(BdKnowledgeCategoryEntity paramT) {
		// TODO 自动生成的方法存根
		JSONObject fromObject = JSONObject.fromObject(paramT);
		BdKnowledgeCategoryEntity kmCategoryEntity = (BdKnowledgeCategoryEntity) fromObject
				.toBean(fromObject, BdKnowledgeCategoryEntity.class);
		return bdKmCategoryEntityDao.insertSelective(kmCategoryEntity);
	}

	public BdKnowledgeCategoryEntity selectByPrimaryKey(String paramString) {
		// TODO 自动生成的方法存根
		return bdKmCategoryEntityDao.selectByPrimaryKey(paramString);
	}

	public int updateByPrimaryKey(BdKnowledgeCategoryEntity paramT) {
		// TODO 自动生成的方法存根
		JSONObject fromObject = JSONObject.fromObject(paramT);
		BdKnowledgeCategoryEntity kmCategoryEntity = (BdKnowledgeCategoryEntity) fromObject
				.toBean(fromObject, BdKnowledgeCategoryEntity.class);
		return bdKmCategoryEntityDao.updateByPrimaryKey(kmCategoryEntity);
	}

	public List selectByCondition(String paramString) {
		// TODO 自动生成的方法存根
		return bdKmCategoryEntityDao.selectByCondition(paramString);
	}

	public int countByCondition(String paramString) {
		// TODO 自动生成的方法存根
		return bdKmCategoryEntityDao.countByCondition(paramString);
	}

	public int deleteByCondition(String paramString) {
		// TODO 自动生成的方法存根
		return bdKmCategoryEntityDao.countByCondition(paramString);
	}

	public int insertSelective(BdKnowledgeCategoryEntity paramT) {
		// TODO 自动生成的方法存根
		JSONObject fromObject = JSONObject.fromObject(paramT);
		BdKnowledgeCategoryEntity kmCategoryEntity = (BdKnowledgeCategoryEntity) fromObject
				.toBean(fromObject, BdKnowledgeCategoryEntity.class);
		return bdKmCategoryEntityDao.insertSelective(kmCategoryEntity);
	}

	public int updateByPrimaryKeySelective(BdKnowledgeCategoryEntity paramT) {
		// TODO 自动生成的方法存根
		JSONObject fromObject = JSONObject.fromObject(paramT);
		BdKnowledgeCategoryEntity kmCategoryEntity = (BdKnowledgeCategoryEntity) fromObject
				.toBean(fromObject, BdKnowledgeCategoryEntity.class);
		return bdKmCategoryEntityDao
				.updateByPrimaryKeySelective(kmCategoryEntity);
	}
	
	public List<BdKnowledgeCategoryEntityVo> selectUserRole(Map map){
		return bdKmCategoryEntityDao.selectUserRole(map);
	}
}
/*
class TestMain {
	public static void main(String[] args) {
		// 获取服务的实现类
		ProductServiceImpl impl = IuapFacade.getInstance()
				.getProductServiceImpl();
		// 创建对应的实体类，应该是模仿请求类的
		BdProductEntity provo = new BdProductEntity();
		// 为实体类设置数据
		provo.setProduct_name("测试产品1");

		// 请求对象，用于封装相应的参数
		RequestDto reqDto = new RequestDto();
		reqDto.setPageNum(0);
		reqDto.setPageSize(15);
		reqDto.setPk_user("pk_zhangsan");
		reqDto.setParams(JsonUtils.toJsonStr(provo));

		// 结果数据封装类
		// 传入请求参数，返回结果，典型的，都是通过封装的形式
		ResultDto rs = impl.queryCondition(reqDto);
		System.out.print("reqDto:" + JsonUtils.toJsonStr(reqDto));
		System.out.print("rs:" + JsonUtils.toJsonStr(rs));
		List<BdProductEntity> listvo = null;
		try {
			listvo = (List<BdProductEntity>) JsonUtils.jsonToList(rs.getData()
					.toString(), BdProductEntity.class);
		} catch (Exception e) {
			// TODO 自动生成的 catch 块
			e.printStackTrace();
		}
		System.out.print("查询到数据量：" + listvo == null ? 0 : listvo.size());

	}

}*/
